<?php

/**
 * 清空审核数据
 */

namespace app\crontab\controller\once;


use app\crontab\model\HouseAuction;
use custom\Log;
use custom\Mongo;
use custom\Redis;
use app\common\lib\RedisKey;
use app\common\lib\RespCode;
use map\BaiDu;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
use app\crontab\model\House as HouseModel;

class Delaudit extends Command {


    protected function configure() {
        $this->setName('Delaudit');
    }

    protected function execute(Input $input, Output $output) {
        $this->initial();
    }

    public function initial() {
        echo "starting\n";
        //经纪人id集合
        $agent_ids = db('company_agent')->where("is_audit=1")->column('id');
        //经纪人与用户关联表数据集合
        $agent_users = db('company_agent_user')->field('id,user_id')->where('agent_id', 'in', $agent_ids)->select();
        //关联表id集合
        $agent_user_ids = array_column($agent_users, 'id');
        //关联用户id集合
        $user_ids = array_column($agent_users, 'user_id');
        //1.删除推荐房源数据
        db('recommend_house')->where('agent_id', 'in', $agent_ids)->delete();
        //2.删除房源提醒数据
        db('agent_remind')->where('agent_id', 'in', $agent_ids)->delete();
        //3.删除经纪人动态表数据
        db('agent_trends')->where('agent_id', 'in', $agent_ids)->delete();
        //4.删除用户跟进记录表数据
        db('agent_follow_log')->where('agent_user_id', 'in', $agent_user_ids)->delete();
        //5.删除互动记录表数据
        db('agent_user_interaction_log')->where('agent_user_id', 'in', $agent_user_ids)->delete();
        //6.删除经纪人提交反馈数据
        db('company_agent_problem')->where('agent_id', 'in', $agent_ids)->delete();
        //7.删除经纪人足迹表数据
        db('agent_track')->where('agent_id', 'in', $agent_ids)->delete();
        //8.删除经纪人定制需求表数据
        db('agent_demand')->where('agent_id', 'in', $agent_ids)->delete();
        //9.删除法拍百科点赞表数据
        db('wiki_give_agent')->where('agent_id', 'in', $agent_ids)->delete();
        //10.删除经纪人智能选房消息通知表数据
        db('message_agent_house')->where('agent_id', 'in', $agent_ids)->delete();
        //11.删除经纪人系统消息表数据
        db('message_agent_system')->where('agent_id', 'in', $agent_ids)->delete();
        //12.删除用户表数据
        db('company_user')->where('id', 'in', $user_ids)->delete();
        //13.删除经纪人与用户关联表
        db('company_agent_user')->where('id', 'in', $agent_user_ids)->delete();
        //14.删除经纪人表数据
        db('company_agent')->where('id', 'in', $agent_ids)->delete();

        echo "end\n";
    }

}
